﻿$().ready(function () {
    function getStudentList(urlParam) {
        $.ajax({
            type: "GET",
            url: urlParam,
            success: showResponse,
            dataType: "html"
        });
    }

    function showResponse(response) {
        $("#updatedContainer").html(response);
    }
    
    $("#studyGroupSelect").change(function () {
        var actionUrl = $(this).data("student-list-url") + "?groupId=" + $(this).val();
        getStudentList(actionUrl);
        $("#study-group-title").html($(this).text() + " - " + $("#study-group-title").html());
    });
    
    if ($("#studyGroupSelect").length == 1) {
        var url = $("#studyGroupSelect").data("student-list-url") + "?groupId=" + $("#studyGroupSelect option:first").val();
        getStudentList(url);
        $("#study-group-button-panel").html($("#studyGroupSelect option:first").text() + " - " + $("#study-group-button-panel").html());
    }
    else {
        $("#studyGroupSelect").show();
    }
});